import 'dart:convert';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:common_utils/common_utils.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:taonile/config/config.dart';
import 'package:taonile/entity/user_info_entity.dart';
import 'package:taonile/provider/userinfo_provider.dart';
import 'package:taonile/utils/user_utils.dart';
import 'package:taonile/views/default_views.dart';
import 'package:taonile/views/dialog_manager.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:toggle_switch/toggle_switch.dart';

import '../entity/my_collect_entity.dart';
import '../http/api.dart';
import '../routers/routers.dart';
import 'home_market_coin.dart';
import 'home_market_stock.dart';
import 'order_list.dart';

class HomeMarket extends StatefulWidget {
  const HomeMarket({Key? key}) : super(key: key);

  @override
  State<HomeMarket> createState() => _HomeMarketState();
}

class _HomeMarketState extends State<HomeMarket> {
  int _currentIndex = 0;

  List<Widget> tabViews = [
    HomeMarketCoin(),
    HomeMarketStock(),
  ];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Config.colorBg,
      appBar: AppBar(
        title: ToggleSwitch(
          minWidth: 180.w,
          minHeight: 60.w,
          cornerRadius: 30.w,
          initialLabelIndex: _currentIndex,
          totalSwitches: 2,
          fontSize: 24.w,
          inactiveBgColor: const Color(0xFFEEEEEE),
          labels: const ['区块行情', '股票行情'],
          onToggle: (index) {
            setState(() {
              _currentIndex = index!;
            });
          },
        ),
        centerTitle: true,
      ),
      body: Container(
        margin: EdgeInsets.only(top: 0.w),
        child: IndexedStack(
          index: _currentIndex,
          children: tabViews,
        ),
      ),
    );
  }
}
